<?php

namespace app\api\logic;

use app\common\enum\notice\EmailEnum;
use app\common\logic\BaseLogic;
use app\common\service\EmailService;


/**
 * 邮箱逻辑
 * Class EmailLogic
 * @package app\api\logic
 */
class EmailLogic extends BaseLogic
{

    /**
     * @notes 发送邮箱验证码
     * @param $params
     * @return false|mixed
     * @author 段誉
     * @date 2022/9/15 16:17
     */
    public static function sendCode($params)
    {
        try {
            $scene_id = $params['scene'];
            $scene_desc = EmailEnum::getSceneDesc($scene_id);
            if (empty($scene_desc)) {
                throw new \Exception('场景值异常');
            }

            $data = [
                'scene_id' => $scene_id,
                'scene_desc' => $scene_desc,
                'code' => mt_rand(1000, 9999),
                'user_email' => $params['email'],
            ];
            return EmailService::send($data);

        } catch (\Exception $e) {
            self::$error = $e->getMessage();
            return false;
        }
    }

}